<template>
	<view v-if="imgHost" :style="theme">
		<Homepage v-show="tabIndex == '/pages/index/index'" ref="homepageRef" @bacBtn="bacBtn" />
		<Homes v-show="tabIndex == '/pages/home/index'" ref="homeRef" />
		<EntranceAndExit v-show="tabIndex == '/pages/venue/entranceAndExit'" ref="exitRef" />
		<Curriculum v-show="tabIndex == '/pages/curriculum/index'" ref="curriculumRef" />
		<Activity v-show="tabIndex == '/pages/activity/index'" ref="activityRef" />
		<Tabber :value="tabIndex" @bacBtn="bacBtn" />
	</view>
</template>

<script>
	import Tabber from "@/components/tabber.vue";
	import Homepage from "@/components/tab/index.vue";
	import Homes from "@/components/tab/home.vue";
	import Activity from "@/components/tab/activity.vue";
	import EntranceAndExit from "@/components/tab/exit.vue";
	import Curriculum from "@/components/tab/curriculum.vue";
	export default {
		components: {
			Tabber,
			Homepage,
			Activity,
			EntranceAndExit,
			Curriculum,
			Homes
		},
		data() {
			return {
				tabIndex: '',
				teacherId: ''
			}
		},
		async onLoad(ops) {
			await this.$onLaunched;
			this.tabIndex = ops.url || '/pages/index/index'
			this.teacherId = ops.teacherId
			this.getCG()
			const scene = decodeURIComponent(ops.scene)
			if (scene && scene != 'undefined') {
				uni.setStorage({
					key: 'shareMemberId',
					data: scene
				});
				if (this.userInfo) {
					this.addShareMemberRelevance(scene)
				}
			}
		},
		async onShow() {
			await this.$onLaunched;
			if (this.tabIndex === '/pages/index/index') {
				this.$refs.homepageRef.showTab(1)
			} else if (this.tabIndex === '/pages/home/index') {
				this.$refs.homeRef.showTab()
			} else if (this.tabIndex === '/pages/activity/index') {
				this.$refs.activityRef.searchBtn()
			} else if (this.tabIndex === '/pages/curriculum/index') {
				if (this.teacherId) {
					this.$refs.curriculumRef.tabclick({
						index: 1,
						onTeach: [this.teacherId]
					})
				} else {
					this.$refs.curriculumRef.tabclick({
						index: 0
					})
				}
			} else if (this.tabIndex === '/pages/venue/entranceAndExit') {
				this.$refs.exitRef.getList()
			}
		},
		methods: {
			bacBtn(e) {
				this.tabIndex = e
				if (e === '/pages/index/index') {
					this.$refs.homepageRef.showTab()
				} else if (this.tabIndex === '/pages/home/index') {
					this.$refs.homeRef.showTab()
				} else if (this.tabIndex === '/pages/activity/index') {
					this.$refs.activityRef.searchBtn()
				} else if (this.tabIndex === '/pages/curriculum/index') {
					this.$refs.curriculumRef.tabclick({
						index: 0
					})
				} else if (this.tabIndex === '/pages/venue/entranceAndExit') {
					this.$refs.exitRef.getList()
				}
			},
			// 获取场馆 更新场馆id以及场馆名称
			getCG() {
				this.$app.ajax({
					data: {
						param: {
							lat: '',
							lng: '',
							openStatus: '1'
						}
					},
					api: this.$api.getVenue()
				}).then((res) => {
					if (res.errorCode === '000000') {
						let arr = res.recordList
						let index = 0
						if (this.venueId) {
							arr.forEach((e, dex) => {
								if (e.id === this.venueId) {
									index = dex
								}
							})
						}
						this.$store.commit('setVenueName', res.recordList[index].name);
						this.$store.commit('setVenueId', res.recordList[index].id);
						this.$store.commit('setVenuephone', res.recordList[index].telephone);
						this.$store.commit('setAlbumStatus', res.recordList[index].albumStatus);
						this.$refs.homepageRef.showTab('start')
					}
				}).catch(() => {})

			},
			addShareMemberRelevance(shareMemberId) {
				this.$app.ajax({
					data: {
						param: {
							shareMemberId
						}
					},
					api: this.$api.addShareMemberRelevance()
				}).then((res) => {
					if (res.errorCode === '000000') {
						uni.removeStorageSync('shareMemberId');
					}
				})
			}

		},
		onReachBottom() {
			uni.$emit('onReachBottom');
		},
		onPageScroll(res) {
			// console.log("页面滚动了")
			uni.$emit('onPageScroll', res.scrollTop)
		},
		onShareAppMessage(e) {
			let path = this.tabIndex
			return {
				path: '/pages/index/index?url=' + path // 路径，传递参数到指定页面。
			}
		}

	}
</script>